<!DOCTYPE html>

<?php

/* variables */
$version            = '1.2';
$modificationDate   = '2017-08-16'; 

$appURL         = 'https://www.picdrop.de';
$domainUuid     = 'adedc2c1530a0fb9ed1470efdf4bc4d8';
$title          = 'tece';

$request        = empty($_GET['r']) ? '' : $_GET['r'];
$webIntURL      = null;

/* assemble webintegration URL (Apache) */
$host = empty($_SERVER['HTTP_HOST']) ? null : $_SERVER['HTTP_HOST'];

if($host !== null)
{
    $relPath = null;

    if(!empty($_SERVER["REQUEST_URI"]))
    {
        $dirPath            = str_replace('\\', '/', dirname(__FILE__));
        $dirPathElements    = explode('/', trim($dirPath, '/'));

        $pathElements       = explode('/', trim($_SERVER["REQUEST_URI"], '/'));
        $relPathElements    = array();

        if(empty($pathElements))
        {
            $relPath = '';
        }
        else
        {
            $peCur = 0;
            for ($i = 0, $c = count($dirPathElements); $i < $c; $i++)
            {
                if ($dirPathElements[$i] === $pathElements[$peCur])
                {
                    $relPathElements[] = $dirPathElements[$i];
                    $peCur++;
                }
            }

            $relPath = implode('/', $relPathElements);
        }
    }

    if($relPath !== null) $webIntURL = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . trim($host . '/' . $relPath, '/');
}

/* shorten request by prefix */
if(!empty($_GET['pre']))
{
    $prefix = $_GET['pre'];
    
    if(strncmp($request, $prefix, strlen($prefix)) === 0)
    {
        $request = ltrim(substr($request, strlen($prefix)), '/');
    }
}

/* assemble query params */
$queryParams = $_GET;
if(isset($queryParams['r'])) unset($queryParams['r']);
if(isset($queryParams['pre'])) unset($queryParams['pre']);

if($webIntURL !== null) $queryParams['wi'] = $webIntURL;

/* assemble target url */
$targetURL = $appURL.'/webintegration/gateway/'.$domainUuid.'/'.$request.(empty($queryParams) ? '' : '?'.http_build_query($queryParams));

/* set js vars */
$jsVars = array(
    'version'           => $version,
    'modificationDate'  => $modificationDate,
    
    'appURL'            => $appURL,
    'domainUuid'        => $domainUuid,
    'targetURL'         => $targetURL
);

?>

<!-- PicDrop Web-Integration - v:<?php echo $version;?> (<?php echo $modificationDate;?>) -->

<html>
    <head>
        <title><?php echo $title; ?></title>

        <meta name="robots" content="noindex,nofollow" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
        
        <script type="text/javascript">window.TobyVars = <?php echo json_encode($jsVars); ?>;</script>
        
        <link rel="stylesheet" type="text/css" media="all" href="<?php echo $appURL; ?>/themes/picdrop/css/scopes/webintegration/webintegration.css" />
        <script type="text/javascript" src="<?php echo $appURL; ?>/themes/picdrop/js_built/main/webintegration.js"></script>

    </head>

    <body>
        <iframe src="<?php echo $targetURL; ?>"></iframe>
    </body>
</html>
